﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class bbsshow : System.Web.UI.Page
    {
        int id;
        study.BLL.tb_bbs_note nbll = new study.BLL.tb_bbs_note();
        study.BLL.tb_bbs_note_re rbll = new study.BLL.tb_bbs_note_re();
        study.BLL.tb_user ubll = new study.BLL.tb_user();
        public List<study.Model.tb_bbs_note_re> renotlist;
        protected void Page_Load(object sender, EventArgs e)
        {
          
            if (!IsPostBack)
            {
                Session["MENU_SELECTED"] = 1;
                if (Request.QueryString["id"] == null)
                    Response.Redirect("bbs.aspx");

                id =Convert.ToInt32(Request.QueryString["id"]);
                Databind(id);

            }

        }
        protected void Databind(int id)
        {
            
            DataSet nds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
             strWhere.AppendFormat("ID like '%{0}%'", id);
             nds = nbll.GetList(strWhere.ToString());
             note_title.Text = nds.Tables[0].Rows[0]["title"].ToString();
             time.Text = nds.Tables[0].Rows[0]["post_time"].ToString();
             context.Text = nds.Tables[0].Rows[0]["content"].ToString();

             login_status.uermod =int.Parse( nds.Tables[0].Rows[0]["userId"].ToString());
             login_status.loadover(false);
             StringBuilder strWhere1 = new StringBuilder();

             strWhere1.AppendFormat("noteId like '%{0}%'", id);
           //  DataSet rds = new DataSet(); 
            // rds = rbll.GetList(strWhere1.ToString());
            renotlist = rbll.GetModelList(strWhere1.ToString());

            
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["USER"] == null)
            {
                Response.Write("<script LANGUAGE='javascript'>alert('请先登录！')</script>");
                return;
            }
            study.Model.tb_user umod = (study.Model.tb_user)Session["USER"];
            string content = TextBox1.Text.Trim();
            if (content == null)
            {
                Response.Write("<script LANGUAGE='javascript'>alert('回复不能为空！')</script>");
                return;
            }
            study.Model.tb_bbs_note_re renmod = new study.Model.tb_bbs_note_re();
            renmod.userId = umod.ID;
            renmod.noteId = id;
            renmod.content = content;
            renmod.post_time = DateTime.Today.ToShortDateString();
            rbll.Add(renmod);
            umod.count++;
            ubll.Update(umod);
            Response.Write("<script LANGUAGE='javascript'>alert('回复成功！')</script>");
        }

        protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
        {

                  
        }
        

      

    }
}